import 'element-ui/lib/theme-chalk/display.css'
import 'video.js/dist/video-js.css'

// 配置 fontawesomeIcon 图标库
import { library } from '@fortawesome/fontawesome-svg-core'
import {
  faBackward,
  faBolt,
  faCloud,
  faForward,
  faSnowflake,
  faSun,
  faTemperatureFull,
  faTornado,
  faWind
} from '@fortawesome/free-solid-svg-icons'
import { FontAwesomeIcon } from '@fortawesome/vue-fontawesome'
// 引入 DataV
import {
  borderBox7,
  borderBox12,
  borderBox13,
  capsuleChart,
  decoration2,
  scrollBoard,
  waterLevelPond
} from '@jiaminghi/data-view'
import axios from 'axios'
import * as echarts from 'echarts'
// 引入 element 组件
import { Col, Drawer, Row } from 'element-ui'
import lottie from 'lottie-web'
// pinia
import { createPinia, PiniaVuePlugin } from 'pinia'
import { createPersistedState } from 'pinia-persistedstate-plugin'
import Vue from 'vue'
// 模态框
import vmodal from 'vue-js-modal'
import VueRouter from 'vue-router'
// 视频插件
import VideoPlayer from 'vue-video-player'

import App from './App.vue'
import router from './router'

Vue.use(PiniaVuePlugin)
const pinia = createPinia()
pinia.use(createPersistedState()) //开启缓存，存储在localstorage

Vue.use(vmodal)
Vue.use(VideoPlayer)
// 将 echarts 挂载到原型链上
Vue.prototype.$echarts = echarts
// 挂载 axios
Vue.prototype.$axios = axios

library.add(
  faWind,
  faSun,
  faCloud,
  faBolt,
  faSnowflake,
  faTemperatureFull,
  faTornado,
  faBackward,
  faForward
)

Vue.use(borderBox7)
Vue.use(borderBox13)
Vue.use(borderBox12)
Vue.use(decoration2)
Vue.use(scrollBoard)
Vue.use(capsuleChart)
Vue.use(waterLevelPond)

// 挂载 lottile 动效库
Vue.prototype.$lottie = lottie

// 注入fontawesome组件
Vue.component('font-awesome-icon', FontAwesomeIcon)
// 注入 element 组件
Vue.use(Row)
Vue.use(Col)
Vue.use(Drawer)
// 重写 push 和 replace 方法
const originPush = VueRouter.prototype.push
const originReplace = VueRouter.prototype.replace

VueRouter.prototype.push = function (location, resolve, reject) {
  if (resolve && reject) {
    originPush.call(this, location, resolve, reject)
  } else {
    originPush.call(
      this,
      location,
      () => {},
      () => {}
    )
  }
}
VueRouter.prototype.replace = function (location, resolve, reject) {
  if (resolve && reject) {
    originReplace.call(this, location, resolve, reject)
  } else {
    originReplace.call(
      this,
      location,
      () => {},
      () => {}
    )
  }
}
Vue.use(VueRouter)

Vue.config.productionTip = false

new Vue({
  router,
  pinia,
  mounted() {
    setTimeout(() => {
      if (document.getElementById('loading'))
        document.getElementById('loading').remove()
    }, 1000)
  },
  beforeCreate() {
    Vue.prototype.$bus = this
  },
  render: (h) => h(App)
}).$mount('#app')
